package zsc.liangyi.blog.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import zsc.liangyi.blog.web.interceptor.BaseInterceptor;

/**
 * @Classname WebMvcConfig
 * @Description TODO
 * @Date 2019-3-14 10:01
 * @Created by CrazyStone
 */

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {
    @Autowired
    private BaseInterceptor baseInterceptor;

    @Override
    // 重写addInterceptors()方法，注册自定义拦截器
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(baseInterceptor);
    }

    //配置虚拟路径，文件在本地硬盘，文件路径在数据库存储
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
//        registry.addResourceHandler("/avatar/**").addResourceLocations("file:/blog/user/avatar/");
        registry.addResourceHandler("/images/**").addResourceLocations("file:D://blog/images/**");
        registry.addResourceHandler("/images/user/avatar/**").addResourceLocations("file:D://blog/images/user/avatar/");
        registry.addResourceHandler("/images/category/**").addResourceLocations("file:D://blog/images/category/");
    }
}

